
package com.task.base;

import android.app.ListActivity;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class StatisticsActivity extends ListActivity {

    ArrayList<HashMap<String, String>> data;

    PackageManager mPm;

    SimpleAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.statistics);
        mPm = getPackageManager();
        data = new ArrayList<HashMap<String, String>>();
        adapter = new SimpleAdapter(this, data, R.layout.statistics_list_item, new String[] {
                "app_name", "count", "use_time"
        }, new int[] {
                R.id.app_name, R.id.count, R.id.use_time
        });

        setListAdapter(adapter);
    }

    @Override
    protected void onStart() {
        prepareData();
        super.onResume();
    }

    private void prepareData() {
        data.clear();
        List<ApplicationInfo> installedAppList = mPm
                .getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
        HashMap<String, String> map;
        for (ApplicationInfo applicationInfo : installedAppList) {
            map = new HashMap<String, String>();
            map.put("app_name", mPm.getApplicationLabel(applicationInfo).toString());
            map.put("count", 10 + "");
            map.put("use_time", "10m");
            data.add(map);
        }
        adapter.notifyDataSetChanged();

    }
}
